package com.ruoyi.user.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.ruoyi.common.annotation.EnumConverter;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.core.convert.converter.Converter;

/**
 * 社戒社康人员类型
 */
@Getter
@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.STRING)
public enum UserSjskType {

    /**
     * 社戒
     */
    SJ("0"),

    /**
     * 社康
     */
    SK("1");

    @EnumValue
    private final String userType;

    @JsonValue
    public String getUserType() {
        return userType;
    }

    @EnumConverter
    public static class InnerConverter implements Converter<String, UserSjskType> {
        @Override
        public UserSjskType convert(String source) {
            return getUserType(source);
        }

    }

    public static UserSjskType getUserType(String str) {
        for (UserSjskType value : values()) {
            if (StringUtils.contains(str, value.getUserType())) {
                return value;
            }
        }
        throw new RuntimeException("'UserSjskType' not found By " + str);
    }

}
